package game.targets.entity.world;

import game.targets.MathFuncs;
import game.targets.entity.Entity;
import game.targets.observer.Subject;
import game.targets.room.Room;

import com.badlogic.gdx.math.Vector3;

public class ArrowStatic extends Entity{

	private boolean charge;
	private Vector3 to;
	private Vector3 from;
	private float alpha;
	private float reloadTimer;
	private boolean reloading;
	
	public static float DISTANCE=2;
	public static float RELOAD_TIMER=1;
	
	public ArrowStatic(Vector3 pos, Subject subject) {
		super(pos, new Vector3(0,0,0), ARROW_MODEL, subject);
		charge=false;
		reloading=false;
		this.setScale(0.2f);
	}

	@Override
	public void update(float delta) {
		//move the arrow back when charging
		if(charge){
			Vector3 temp=new Vector3(from);
			this.setPosition(temp.lerp(to, alpha/Room.MAX_CHARGE_TIME));
			alpha+=delta;
		}
		if(reloading){
			reloadTimer+=delta;
			if(reloadTimer > RELOAD_TIMER){
				setInvisible(false);
				reloading=false;
			}
		}
		
	}
	
	public void charge(Vector3 dir){
		to=MathFuncs.getFrontOrBackPosition(this.getPosition(), dir, -DISTANCE);
		from=new Vector3(this.getPosition());
		charge=true;
		alpha=0;
	}
	
	public void hold(){
		charge=false;
	}
	
	public void fire(){
		setInvisible(true);
		alpha=0;
		charge=false;
		reloadTimer=0;
		reloading=true;
	}

}
